package org.gp.core.utils;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.gp.core.entity.Activity;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Created by luoliang on 2017/2/6.
 */
@Slf4j
public class HobbyConvertUtil {

    public static String getHobbyCode(String key) {
        String code = "";
        switch (key) {
            case "JYJH":
                code = "1";
                break;
            case "YYXJ":
                code = "2";
                break;
            case "TYYD":
                code = "3";
                break;
            case "HWLX":
                code = "4";
                break;
            case "JZGY":
                code = "5";
                break;
            default:
                code = "6";
                break;
        }

        return code;
    }

    public static String getHobbyKey(String code) {
        String key = "";
        switch (code) {
            case "1":
                key = "JYJH";
                break;
            case "2":
                key = "YYXJ";
                break;
            case "3":
                key = "TYYD";
                break;
            case "4":
                key = "HWLX";
                break;
            case "5":
                key = "JZGY";
                break;
            default:
                key = "QT";
                break;
        }

        return key;
    }

    public static List<Activity> hobbySort(List<Activity> data, String hobby) {
        List<String> hobbyStr = Arrays.asList(hobby.split(","));//分割解析字符串
        log.debug("兴趣爱好：{}", JSON.toJSONString(hobbyStr));
        if (CollectionUtils.isEmpty(hobbyStr)) {
            return data;
        }
        List<Activity> head = new ArrayList<>(5);
        List<Activity> end = new ArrayList<>(5);
        data.stream().forEach(activity -> {
            if (hobbyStr.contains(getHobbyKey(activity.getLabel()))) {
                head.add(activity);
                log.debug("活动名：" + activity.getName());
            } else {
                end.add(activity);
            }
        });
        head.addAll(end);

        return head;
    }
}
